from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank
from typing import Optional
from module_admin.annotation.pydantic_annotation import as_query


class LlmModel(BaseModel):
    """
    大模型配置表对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description="ID")
    scenario: Optional[str] = Field(default="", description="场景代码")
    model_name: Optional[str] = Field(default=None, description="模型名称")
    model_desc: Optional[str] = Field(default=None, description="模型描述")
    api_key: Optional[str] = Field(default=None, description="API_KEY")
    base_url: Optional[str] = Field(default=None, description="BASE_URL")
    system_prompt: Optional[str] = Field(default=None, description="系统提示词")
    user_prompt: Optional[str] = Field(default=None, description="用户提示词模板")
    used: Optional[int] = Field(default=None, description="是否启用")

    @NotBlank(field_name="scenario", message="场景代码不能为空")
    def get_scenario(self):
        return self.scenario

    @NotBlank(field_name="model_name", message="模型名称不能为空")
    def get_model_name(self):
        return self.model_name

    @NotBlank(field_name="api_key", message="API_KEY不能为空")
    def get_api_key(self):
        return self.api_key

    @NotBlank(field_name="base_url", message="BASE_URL不能为空")
    def get_base_url(self):
        return self.base_url

    @NotBlank(field_name="system_prompt", message="系统提示词不能为空")
    def get_system_prompt(self):
        return self.system_prompt

    @NotBlank(field_name="user_prompt", message="用户提示词不能为空")
    def get_user_prompt(self):
        return self.user_prompt

    def validate_fields(self):
        self.get_scenario()
        self.get_model_name()
        self.get_api_key()
        self.get_base_url()
        self.get_system_prompt()
        self.get_user_prompt()


class LlmQueryModel(LlmModel):
    """
    大模型配置不分页查询模型
    """

    pass


@as_query
class LlmPageQueryModel(LlmQueryModel):
    """
    大模型配置分页查询模型
    """

    page_num: int = Field(default=1, description="当前页码")
    page_size: int = Field(default=10, description="每页记录数")


class DeleteLlmModel(BaseModel):
    """
    删除大模型配置模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    ids: str = Field(description="需要删除的ID")
